import * as echarts from "echarts";

export default function (el) {
  // onMounted(() => {
  //   const echartInstance = echarts.init(el);
  // });
  // window.onload(()=>{
  //   const echartInstance = echarts.init(el);
  // })
  const echartInstance = echarts.init(el);

  const setOptions = (options) => {
    echartInstance.setOption(options);
  };

  // 手动改变echart宽度
  const updateSize = () => {
    echartInstance.resize();
  };

  // 对视口改变时，自动改变echart宽度
  window.addEventListener("resize", () => {
    echartInstance.resize();
  });

  return {
    echartInstance,
    setOptions,
    updateSize,
  };
}
